//
//  NavigateView.m
//  Toyota
//
//  Created by ld on 2024/6/25.
//

#import "NavigateView.h"
#import "Definition.h"
@implementation NavigateView
-(instancetype)initWithFrame:(CGRect)frame andTitleStr:(NSString *)titleStr andRightStr:(NSString *)rightStr andLeftBlock:(void (^)(BOOL hasBlock))leftBlock andRightBlock:(void (^)(BOOL hasBlock))rightBlock {
    self = [super initWithFrame:frame];// 先调用父类的initWithFrame方法
       if (self) {
           [self initWithFrame:frame andTitleStr:titleStr andRightStr:rightStr];
           self.leftBtnBlock = leftBlock;
           self.rightBtnBlock = rightBlock;
       }
    
    return self;
    
}

- (void)initWithFrame:(CGRect)frame andTitleStr:(NSString *)titleStr andRightStr:(NSString *)rightStr {
    UIButton * leftBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    leftBtn.frame = CGRectMake(0, Height_StatusBar, 44, 44);
    [leftBtn setImage:[UIImage imageNamed:@"backNav"] forState:(UIControlStateNormal)];
    [leftBtn setImageEdgeInsets:UIEdgeInsetsMake(12, 12, 12, 12)];
    leftBtn.imageView.contentMode = UIViewContentModeScaleAspectFit;
    [leftBtn addTarget:self action:@selector(leftBtnAction) forControlEvents:(UIControlEventTouchUpInside)];
    [self addSubview:leftBtn];
    
    UILabel * titleLab = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth / 2. - 60, Height_StatusBar, 120, 44)];
    titleLab.text = titleStr;
    titleLab.textAlignment = NSTextAlignmentCenter;
    titleLab.textColor = kColor141414;
    titleLab.font = kBoldFont(17);
    [self addSubview:titleLab];
    
    UIButton * rightBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    rightBtn.frame = CGRectMake(ScreenWidth - 100, Height_StatusBar, 100, 44);
    [rightBtn setTitle:rightStr forState:(UIControlStateNormal)];
    [rightBtn setTitleColor:kColor141414 forState:(UIControlStateNormal)];
    rightBtn.titleLabel.font = fontSize(14);
    [rightBtn addTarget:self action:@selector(rightBtnAction) forControlEvents:(UIControlEventTouchUpInside)];
    [self addSubview:rightBtn];
}

- (void)leftBtnAction{
    if (self.leftBtnBlock) {
        self.leftBtnBlock(YES);
    }
}

-(void)rightBtnAction {
    if (self.rightBtnBlock) {
        self.rightBtnBlock(YES);
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
